package com.hanlink.dsp.ui.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by PeterVon on 2015-11-28.
 */
public class EqIndicatorView extends View {

    private Paint mPaint;
    private float mRadius = 5.0f;

    private Rect mRect = new Rect();
    private int padding = 10;

    private int mOnColor = Color.WHITE;//选中颜色
    private int mOffCoor = Color.GRAY;//


    private int mIndex;

    private int mTotal;


    public EqIndicatorView(Context context) {
        super(context);
    }

    public EqIndicatorView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public EqIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void initView() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        mPaint.setStyle(Paint.Style.FILL);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.getClipBounds(mRect);
        /*float width = (linePadding + mRadius) * mTotal - linePadding;
        int maxWidth = (int) (getMeasuredWidth() * maxPercent);
        if (width > maxWidth) {
            width = maxWidth;
        }
        float cx = (mRect.right - mRect.left - width) / 2;
        float cy = (mRect.bottom - mRect.top) / 2;
        for (int i = 0; i < mTotal; i++) {
            if (i != mIndex) {
                mPaint.setColor(mOffCoor);
            } else {
                mPaint.setColor(mOnColor);
            }
            canvas.drawCircle(cx, cy, mRadius / 2, mPaint);
            cx += mRadius + linePadding;
        }*/
    }

    public int getIndex() {
        return mIndex;
    }

    public void setIndex(int index) {
        if (index < mTotal && index >= 0) {
            this.mIndex = index;
            postInvalidate();
        }
    }

    public int getTotal() {
        return mTotal;
    }

    public void setTotal(int mTotal) {
        this.mTotal = mTotal;
    }
}
